<?if(!defined("PROLOG_INCLUDED") || PROLOG_INCLUDED!==true)die();?>
<?
$arTabs["main"] = Array(
	"ACTIVE",
	"NAME",
	"CATALOG_ID",
	"CATALOG_SECTION_ID",
	"CODE",
	"SORT",
);

$arTabs["preview"] = Array(
	"PREVIEW_PICTURE",
	"PREVIEW_TEXT_TYPE",
	"PREVIEW_TEXT",
);
$arTabs["detail"] = Array(
	"DETAIL_PICTURE",
	"DETAIL_TEXT_TYPE",
	"DETAIL_TEXT",
);
$arTabs["other"] = Array(
	"TAGS",
);
?>
<?isset($arResult["ERRORS"]) ? ShowError($arResult["ERRORS"]) : ''?>
<script type="text/javascript">

	if(window.ixedit){ixedit.deployed = true};
	if(window.jQuery){jQuery(function(){
		(function(){ var target = jQuery('div#catalog'); target.tabs({event:'click'}); })();
		$('div.settings-img').click(function(evt) {
			var divID = this.id;
			var prID = divID.replace(/settings_prop_img_/, '');
			var child = 'div#'+ divID.replace(/img_/, '');
			$(child).dialog({
				bgiframe: true,
				autoOpen: false,
				height: 200,
				modal: true,
				buttons: {
					'Сохранить': function() {
						var DEF_VAL = $('#DEFAULT_VALUE_' + prID);
						$('#settings_prop_' + prID + '_DEFAULT').val(DEF_VAL.val());
						$(this).dialog('close');
					},
					Cancel: function() {
						$(this).dialog('close');
					}
				},
				close: function() {
				}
			});
			$(child).dialog('open');
		});
	})
};
</script>
<form method="post" action="" name="add_catalog_type">
	<div id="catalog" style="width:100%">
		<ul>
			<li><a href="#main">Основное</a></li>
			<li><a href="#preview">Анонс</a></li>
			<li><a href="#detail">Детально</a></li>
			<li><a href="#other">Разное</a></li>
		</ul>
<?foreach($arTabs as $tab => $arTab):?>
	<div id="<?=$tab?>">
	<table class="styled" width="100%" style="margin:0;padding:0"><?// class="form-table">?>
	<?foreach($arTab as $key):?>
			<?$value = $arResult["FIELDS"][$key]?>
			<tr>
				<?if ($key != "DETAIL_TEXT" AND $key != "PREVIEW_TEXT"):?>
					<td class="td-left" style="vertical-align: top"><?=LANG('MODULE_CATALOG_ELEMENTS_'.$key)?>:</td>
					<td class="td-right">
				<?else:?>
					<th colspan="2"><?=LANG('MODULE_CATALOG_ELEMENTS_'.$key)?>:</th>
					</tr>
					<tr>
						<td colspan="2">
				<?endif?>
					<?switch ($value["TYPE"]):
						case 'text':?>
							<input type="text" name="<?=$key?>" size="90" value="<?=$value["VALUE"]?>"/>
						<?break?>
						<?case 'hidden':?>
							<?=$value["VALUE"]?>
							<input type="hidden" name="<?=$key?>" size="60" value="<?=$value["VALUE"]?>"/>
						<?break?>
						<?case 'checkbox':?>
							<input type="checkbox" name="<?=$key?>" value="Y" <?=$value["VALUE"] == "Y" ? 'checked=checked' : ''?>/>
						<?break?>
						<?case 'radio':?>
							<input type="radio" name="<?=$key?>" value="<?=$value["VALUE"]?>"/>
						<?break?>
						<?case 'select':?>
							<select name="<?=$key?>" style="width: 390px">
								<?foreach($value["VALUES"] as $id => $name):?>
									<option value="<?=$id?>" ><?=$name?></option>
								<?endforeach?>
							</select>
						<?break?>
						<?case 'file':?>
							<input type="file" name="<?=$key?>" size="60" value="<?=$value["VALUE"]?>"/>
						<?break?>
						<?case 'textarea':?>
							<?if($key == "DETAIL_TEXT" OR $key == "PREVIEW_TEXT"):?>
								<textarea name="<?=$key?>" cols="125" rows="25"><?=$value["VALUE"]?></textarea>
							<?else:?>
								<textarea name="<?=$key?>" cols="90" rows="5"><?=$value["VALUE"]?></textarea>
							<?endif?>
						<?break?>
					<?endswitch?>
				</td>
			</tr>
	<?endforeach?>
	<?if($tab == "main"):?>
		<?if(!empty($arResult["PROPERTIES"])):?>
			<tr>
				<th colspan="2"><b>Свойства элемента:</b></th>
			</tr>
			<?foreach ($arResult["PROPERTIES"] as $k => $arProp):?>
				<tr>
					<td><?=$arProp["NAME"]?></td>
					<td><input type="text" name="PROPERTY[<?=$arProp["ID"]?>]" value="<?=$arProp["VALUE"]?>" size="90" /></td>
				</tr>
			<?endforeach?>
		<?endif?>
	<?endif?>
	</table>
</div>
<?endforeach?>
	
	<div class="form-table-buttons">
		<?if ($arResult["MODE"] == "ADD"):?>
			<input type="submit" class="button" name="add_btn" value="<?=LANG('MODULE_CATALOG_ELEMENTS_ADD_TEXT')?>"/>&nbsp;
		<?else:?>
			<input type="submit" class="button" name="edit_btn" value="<?=LANG('MODULE_CATALOG_ELEMENTS_EDIT_TEXT')?>"/>&nbsp;
			<input type="submit" class="button" name="apply_btn" value="<?=LANG('MODULE_CATALOG_ELEMENTS_APPLY_TEXT')?>"/>&nbsp;
		<?endif?>
		<button class="button" onClick="return RedirectTo('/system/admin/catalog/elements.php?TYPE=<?=sXss($_GET['TYPE'])?>&CATALOG_ID=<?=intVal($_GET['CATALOG_ID'])?>')"><?=LANG('MODULE_CATALOG_ELEMENTS_CANCEL_TEXT')?></button>
	</div>
</div>
</form>